/***************************************************************************
 *   Copyright (C) 2008 - 2009 by Pavel Andreev                            *
 *   Mail: apavelm on gmail point com (apavelm@gmail.com)                  *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/


#ifndef DIRCOMPARE_H
#define DIRCOMPARE_H

#include <QtGui>
#include <QtCore>

#include "../foldercmp.h"

#include "ui_dirCompare.h"

class CompareTreeItem
{
public:
	CompareTreeItem(const QList<QVariant> &data, CompareTreeItem *parent = 0);
	~CompareTreeItem();

	void appendChild(CompareTreeItem *child);

	CompareTreeItem *child(int row);
	int childCount() const;
	int columnCount() const;
	QVariant data(int column) const;
	int row() const;
	CompareTreeItem *parent();

private:
	QList<CompareTreeItem*> childItems;
	QList<QVariant> itemData;
	CompareTreeItem *parentItem;
};

class DirCompareModel : public QAbstractListModel
{
	Q_OBJECT
public:
	DirCompareModel(	QObject * parent,
						const QString& left,
						const QString& right,
						const QString& filter = QString::null,
						bool isRecursive = true,
						bool onlyDifferences = true
						);
	~DirCompareModel();

	QVariant data(const QModelIndex &index, int role) const;
	Qt::ItemFlags flags(const QModelIndex &index) const;
	QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
	QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
	QModelIndex parent(const QModelIndex &index) const;
	int rowCount(const QModelIndex &parent = QModelIndex()) const;
	int columnCount(const QModelIndex &parent = QModelIndex()) const;

private:
	void setupModelData(const QStringList &lines, CompareTreeItem *parent);
	
	CompareTreeItem *rootItem;
	QString m_left, m_right, m_filter;
	bool m_recursive, m_onlyDifferences;
};


class DirCompareCtrl : public QWidget, public Ui::DirCompare
{
	Q_OBJECT
public:
	DirCompareCtrl(	QWidget * parent, 
					const QString& strLeft, 
					const QString& strRight,
					const QString& strFilter = QString::null,
					bool showOnlyDifferences = true,
					bool isRecursive = true);
	
};


#endif

